import axios from "axios";

export function request1(config) {
  const instance = axios.create({
    baseURL: "http://api-hmugo-web.itheima.net/api/public/v1",
    timeout: 5000,
  });

  //请求拦截 应用：config不符合服务器要求、发送时显示请求图标、登录携带特殊信息(token)
  instance.interceptors.request.use(
    (config) => {
        // console.log(config);
      return config;
    },
    (err) => {
      console.log(err);
    }
  );

  //响应拦截
  instance.interceptors.response.use(
    (res) => {
        // console.log(res.data);
        let jobj= JSON.stringify(res.data)//获取对象转成字符串
        let obj2=jobj.replace(/https/g,"http")//替换字符
        let oobj=JSON.parse(obj2)//转回去

      return oobj;
    },
    (err) => {
      console.log(err);
    }
  );
  return instance(config);
}
